#define  _CRT_SECURE_NO_WARNINGS 1
#include"List.h"

LTNode* LTNodeInit()
{
	LTNode* phead = (LTNode*)malloc(sizeof(LTNode));
	phead->prev = phead;
	phead->next = phead;
	phead->data = 0;
	return phead;
}

void LTNodePushBack(LTNode* phead,datatype x)
{
	LTNode* newnode = (LTNode*)malloc(sizeof(LTNode));
	if (newnode == NULL)
	{
		perror("malloc fail");
		return;
	}
	newnode->data = x;
	newnode->next = NULL;
	LTNode* prev = phead->prev;
	prev->next = newnode;
	newnode->prev = prev;
	newnode->next = phead;
	phead->prev = newnode;
	return ;
}

void LTNodePushFront(LTNode* phead,datatype x)
{
	LTNode* newnode = (LTNode*)malloc(sizeof(LTNode));
	if (phead == NULL)
	{
		perror("malloc fail");
		return 0;
	}
	newnode->data = x;
	LTNode* next = phead->next;
	phead->next = newnode;
	newnode->prev = phead;
	next->prev = newnode;
	newnode->next = next;
    return ;
}

void LTNodePopBack(LTNode* phead)
{
	LTNode* prev = phead->prev;
	prev->prev->next = phead;
	phead->prev = prev->prev;
	free(prev);
	prev = NULL;
	return;
}

void LTNodePopFront(LTNode* phead)
{
	LTNode* next = phead->next;
	phead->next = next->next;
	next->prev = phead;
	free(next);
	next = NULL;
	return;
}

void PrintfLTNode(LTNode* phead)
{
	LTNode* current = phead->next;
	while (current != phead)
	{
		printf("%d->", current->data);
		current = current->next;
	}
	printf("\n");

	return;
}